# ------------------------------------------------------------------------------------------------
### Generate Table 11: Effects excluding municipalities proposing but not adopting
# ------------------------------------------------------------------------------------------------

# Load data
load("../data/results/sdid_results.Rda")

# Filter and prepare data - exclude unadopted resolutions
filtered_results <- filter_sdid_results(
  sdid_results,
  outcome_filter = c("Overall Turnout", "Party Turnout"),
  party_filter = c("Opposition", "Overall Turnout", "Law and Justice (PiS)"),
  noproposed_sample_filter = "No Proposed"
) %>%
  mutate(
    outcome = case_when(
      outcome == "Party Turnout" & party == "Opposition" ~ "Opposition Turnout",
      outcome == "Party Turnout" & party == "Law and Justice (PiS)" ~ "Government Turnout",
      TRUE ~ outcome
    ),
    outcome = factor(outcome, levels = c("Overall Turnout", "Opposition Turnout", "Government Turnout")),
    sample = ifelse(sample == "< 50km Sample", "$<$ 50km Sample", sample),
    sample = factor(sample, levels = c("$<$ 50km Sample", "Full Sample"))
  ) %>%
  arrange(outcome)

# Generate and save table
latex_table <- create_latex_table(
  filtered_results,
  group_var = "outcome",
  row_var = "sample",
  caption = "Synthetic Difference-in-Differences Estimates Excluding Proposing Municipalities",
  label = "tab:sdid_no_proposing",
  col_names = c("Outcome", "Sample", "Estimate (SE)", "N")
)

save_table(latex_table, "../output/tables/table11.txt")
